package com.sina.shop.manage.controller.log;

import com.sina.shop.domain.log.Log;
import com.sina.shop.manage.service.log.LogManageService;
import com.sina.shop.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2018-01-12-10:34
 */
@Controller
@RequestMapping("logManage")
public class LogManageController extends BaseController {

    @Autowired
    @Qualifier("logManageService")
    private LogManageService logManageService;

    @RequestMapping(value = "getLogList", method = RequestMethod.GET)
    public ModelAndView getLogList(@Valid Log log) {
        LOG.info("log:{}", log);

        ModelAndView mv = new ModelAndView("resultView");
        Map<String, Object> result = new HashMap<>(6);
        Long count[] = new Long[1];
        List<Map<String, Object>> permissionList = logManageService.getLogList(log, count);

        Map<String, Object> data = new HashMap<>(4);
        data.put("recordsTotal", count[0]);
        data.put("recordsFiltered", count[0]);
        data.put("data", permissionList);

        result.put(CODE, OK);
        result.put(DATA, data);
        mv.addObject(RESULT, result);

        return mv;
    }

    @RequestMapping(value = "getLogListToHtml", method = RequestMethod.GET)
    private ModelAndView getLogListToHtml() {

        ModelAndView mv = new ModelAndView("log/logList");

        return mv;
    }
}
